package everyday.leetcode;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author: wenjingyuan
 * @Date: 2022/11/11/16:56
 * @Description:每日一题1704
 *判断字符串的两半是否相似
 * https://leetcode.cn/problems/determine-if-string-halves-are-alike/
 */
public class Num1704 {
    public boolean halvesAreAlike(String s) {
        //首先我们需要将所有的元音字母进行转存
        Set<Character> set=new HashSet<>();
        for(char c:"aeiouAEIOU".toCharArray()){
            set.add(c);
        }
        //其次我们应该判断s的两半中分别有几个元音
        char[] c=s.toCharArray();
        int a=0;
        for (int i = 0; i < s.length()/2; i++) {
            if(set.contains(c[i])){
                a++;
            }
        }
        int b=0;
        for (int i = s.length()-1; i >=s.length()/2; i--) {
            if(set.contains(c[i])){
                b++;
            }
        }
       return a==b;
    }
}
